package com.projectzqjz.parttimework.ui.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.text.InputFilter;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;

import com.projectzqjz.parttimework.App;
import com.projectzqjz.parttimework.R;
import com.projectzqjz.parttimework.base.BaseActivity;
import com.projectzqjz.parttimework.utils.DataCheckUtils;
import com.projectzqjz.parttimework.utils.NewsToastUtils;
import com.projectzqjz.parttimework.utils.ScreenUtil;
import com.projectzqjz.parttimework.utils.TitleBuilder;

import butterknife.BindView;
import butterknife.OnClick;

public class PartEditorActivity extends BaseActivity {
    @BindView(R.id.ed_referralCode)
    EditText ed_referralCode;//填写编辑页
    private String title;

    @Override
    public void setListen() {

    }

    @Override
    public void setTitleBarColor() {

    }

    @Override
    protected boolean isStatusBarBlack() {
        return true;
    }

    @OnClick({R.id.iv_confirm
    })
    public void onViewClicked(View view) {
        if (ScreenUtil.isFastClick()) {
            return;
        }
        switch (view.getId()) {
            case R.id.iv_confirm: //保存修改值
                String str = ed_referralCode.getText().toString().trim();
                if ("".equals(str)) {
                    NewsToastUtils.showToast(App.getContext(), "你输入的" + title + "为空！");
                } else {
                    if (title.equals("手机号码")) {
                        if (!DataCheckUtils.isCellphone(str)) {
                            NewsToastUtils.showToast(PartEditorActivity.this, "请输入正确的手机号！");
                        } else {
                            Intent it = new Intent();
                            it.putExtra("name", str);
                            setResult(RESULT_OK, it);
                            finish();
                        }
                        //需要进行手机号码验证
                    } else if (title.equals("邮箱")) {
                        //需要进行邮箱验证
                        if (DataCheckUtils.isEmail(str)) {
                            Intent it = new Intent();
                            it.putExtra("name", str);
                            setResult(RESULT_OK, it);
                            finish();
                        } else {
                            NewsToastUtils.showToast(PartEditorActivity.this, "请输入正确的邮箱！");
                        }
                    } else {
                        Intent it = new Intent();
                        it.putExtra("name", str);
                        setResult(RESULT_OK, it);
                        finish();
                    }
                }

                break;

        }
    }

    @Override
    public int intiLayout() {
        return R.layout.activity_part_editor_work;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void initView() {
        Intent it = getIntent();
        title = it.getStringExtra("title");
        ed_referralCode.setHint("请输入" + title);
        assert title != null;
        if (title.equals("手机号码")) {
            ed_referralCode.setInputType(InputType.TYPE_CLASS_PHONE);
            ed_referralCode.setFilters(new InputFilter[]{new InputFilter.LengthFilter(11)}); //限制输入位数
        }
        new TitleBuilder(this).setTitleText(title)
                .setLeftIcoListening(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        finish();
                    }
                });

    }

    @Override
    public void initData() {

    }
}
